package topo.action;

import com.zhtelecom.nms.framework.discover.ResourceInfo;
import java.awt.event.ActionEvent;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.JList;
import topo.MainFrame;
import topo.autosearch.NodeResourceSearch;
import topo.data.NodeDevice;
import topo.dialog.ResourcesSearchDialog;
import topo.table.ObjectTableDesc;
import topo.table.ObjectTableModel;
import topo.utils.DialogTools;

public class ResourcesSearchAction extends AbstractAction {
    public ResourcesSearchAction() {
        super("搜索设备资源");
    }

    public void actionPerformed(ActionEvent e) {
        MainFrame.sourceCodeList.setSelectedValue(getValue("Name"), true);

        NodeDevice nodeDevice = (NodeDevice) getValue("ActionDataKeyName");

        ObjectTableDesc tableDesc = new ObjectTableDesc() {
            public Object[] getcolumnNames() {
                String[] cols = { "资源名称", "资源类型", "资源参数", "RSID值", "描述信息", "备注信息" };
                return cols;
            }

            public Object[] getRowDatas(Object obj) {
                ResourceInfo resourceInfo = (ResourceInfo) obj;
                Object[] viDatas = { resourceInfo.getResourceName(), resourceInfo.getResourceTypeName(), resourceInfo.getResourceParam(), resourceInfo.getResourceRSIDValue(), resourceInfo.getResourceDesc(), resourceInfo.getResrouceRemarks() };
                return viDatas;
            }

            public Class getTableObjectClass() {
                return ResourceInfo.class;
            }
        };
        ObjectTableModel tableModel = new ObjectTableModel(tableDesc);
        try {
            List rsList = new NodeResourceSearch().getResourceOfNode(nodeDevice);

            tableModel.addRowObject(rsList);

            if (rsList.size() <= 0) {
                DialogTools.showOkMsg(MainFrame.mainFrame, "消息提示", "未发现设备资源");
                return;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            DialogTools.showErroMsg(MainFrame.mainFrame, "查看设备资源出错!");

            ResourcesSearchDialog dialog = new ResourcesSearchDialog(nodeDevice, tableModel);
            DialogTools.dialogPack(MainFrame.frame, dialog);
        }
    }
}